﻿<Window x:Class="WikiWriter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:p="http://markupprogramming.codeplex.com/markup/programming"
        xmlns:local="clr-namespace:WikiWriter"
        Name="Window" Title="Wiki Writer" Height="800" Width="800"
        local:WindowSettings.Save="True">
    <Window.Resources>
        <local:ViewModel x:Key="ViewModel"/>
        <local:View x:Key="View"/>
        <p:ResourceCommand x:Key="SaveCommand">
            var CanExecute() return true;
            var Execute($parameter) @FindResource('View').Save();
        </p:ResourceCommand>
    </Window.Resources>
    <Window.DataContext>
        <Binding Source="{StaticResource ViewModel}"/>
    </Window.DataContext>
    <Window.CommandBindings>
        <p:ResourceCommandBinding Command="Save" HandlerCommand="{StaticResource SaveCommand}"/>
    </Window.CommandBindings>
    <p:Attached.Operations>
        <p:ScriptHandler Path="Loaded">
            $view = @FindResource('View');
            $view.ArticleSelector = @FindElement('ArticleSelector');
            $view.Text = @FindElement('Text');
            $view.Browser = @FindElement('Browser');
            $view.Status = @FindElement('Status');
            $view.ViewModel = @AssociatedObject.DataContext;
            $view.LoadArticles();
        </p:ScriptHandler>
    </p:Attached.Operations>
    <DockPanel>
        <ToolBarTray DockPanel.Dock="Top" Background="White">
            <ToolBar Band="1">
                <TextBlock Text="Article:" VerticalAlignment="Center"/>
                <ComboBox Name="ArticleSelector" Width="200">
                    <p:Attached.Operations>
                        <p:ScriptHandler>
                            SelectionChanged => @FindResource('View').SelectArticle(@AssociatedObject.SelectedItem);
                        </p:ScriptHandler>
                    </p:Attached.Operations>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <Button Content="Preview" p:Attached.Operations="Click => @FindResource('View').Preview()"/>
                <Button Content="Edit" p:Attached.Operations="Click => @FindResource('View').Edit()"/>
                <Button Content="Save" p:Attached.Operations="Click => @FindResource('View').Save()"/>
                <Button Content="Publish" p:Attached.Operations="Click => @FindResource('View').Publish()"/>
                <Button Content="Check" p:Attached.Operations="Click => @FindResource('View').Check()"/>
                <Button Content="Publish All" p:Attached.Operations="Click => @FindResource('View').PublishAll()"/>
                <Button Content="Check All" p:Attached.Operations="Click => @FindResource('View').CheckAll()"/>
            </ToolBar>
        </ToolBarTray>
        <StatusBar DockPanel.Dock="Bottom">
            <TextBlock VerticalAlignment="Center" Text="Status"/>
            <TextBlock Name="Status" VerticalAlignment="Center"/>
        </StatusBar>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="10"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <ScrollViewer>
                <TextBox Grid.Row="0" Name="Text" AcceptsReturn="True" TextWrapping="Wrap"
                         FontFamily="Lucida Console" FontSize="14"
                         Text="{Binding SelectedText, UpdateSourceTrigger=PropertyChanged}"/>
            </ScrollViewer>
            <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch"/>
            <WebBrowser Grid.Row="2" Name="Browser"/>
        </Grid>
    </DockPanel>
</Window>
